package mil.af.amc.adpetracker.web.actions.EquipmentItem;

import mil.af.amc.adpetracker.web.actions.AbstractAction;
import mil.af.amc.adpetracker.service.EquipmentItemService;
import mil.af.amc.adpetracker.model.EquipmentItem;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.DynaActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Please Fill in this Javadoc
 *
 * @author TSgt Jason Ferguson
 */

public class UpdateLocationAction extends AbstractAction {

    private EquipmentItemService equipmentItemService;

    public void setEquipmentItemService(EquipmentItemService equipmentItemService) {
        this.equipmentItemService = equipmentItemService;
    }

    @Override
    public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {


        DynaActionForm form = (DynaActionForm) actionForm;
        int id = (Integer) form.getMap().get("itemId");
        String location = (String) form.getMap().get("location");

        EquipmentItem item = equipmentItemService.getById(id);

        equipmentItemService.updateLocation(item, location);

        return actionMapping.getInputForward();
    }
}
